home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
-
-
-
- PRODUCT : Borland C++ NUMBER : 1032
- VERSION : 3.x
- OS : DOS
- DATE : October 23, 1992 PAGE : 1/4
-
- TITLE : Example of Mouse Programming in Graphics Mode.
-
-
-
-
-
-
- // This is a very simple drawing program which demonstrates
- // using the mouse by polling the mouse driver; all done with
- // interrupt 0x33 functions.
-
- #include <dos.h>
- #include <stdio.h>
- #include <conio.h>
- #include <graphics.h>
-
- #define MOUSE 0x33
- #define BUT1PRESSED 1
- #define BUT2PRESSED 2
- #define TRUE 1
- #define FALSE 0
-
-
-
- void ActivMouse()
- {
- /* activate mouse */
- _AX=32;
- geninterrupt(MOUSE);
- }
-
-
-
- int ResetMouse()
- {
- /* mouse reset */
- _AX=0;
- geninterrupt(MOUSE);
- return(_AX);
- }
-
-
-
- void ShowMouse()
- {
- /* turn on mouse cursor */
- _AX=1;
- geninterrupt(MOUSE);
-
-
-
-
-
-
-
-
-
-
-
-
-
- PRODUCT : Borland C++ NUMBER : 1032
- VERSION : 3.x
- OS : DOS
- DATE : October 23, 1992 PAGE : 2/4
-
- TITLE : Example of Mouse Programming in Graphics Mode.
-
-
-
-
- }
-
-
-
- void HideMouse()
- {
- /* turn off mouse cursor */
- _AX=2;
- geninterrupt(MOUSE);
- }
-
-
-
- void ReadMouse(int *v,int *h,int *but)
- {
- int temp;
- _AX=3;
- geninterrupt(MOUSE);
-
- // which buttons pressed: 1=left, 2=right, 3=both
- temp=_BX;
- *but=temp;
-
- // horizontal coordinates
- *h =_CX;
-
- // vert coordinates
- *v=_DX;
- }
-
-
-
- int main( void )
- {
- int gdriver = EGA, gmode=EGAHI, errorcode;
- int mouseX, mouseY, mouseButton=0, currentColor=1;
- int oldMouseX=0, oldMouseY=0;
- char button1Down,button2Down=FALSE;
- if (!ResetMouse())
- {
- printf("No Mouse Driver!");
- return(1);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- PRODUCT : Borland C++ NUMBER : 1032
- VERSION : 3.x
- OS : DOS
- DATE : October 23, 1992 PAGE : 3/4
-
- TITLE : Example of Mouse Programming in Graphics Mode.
-
-
-
-
- printf( "Instructions:\nHold down left button to draw,\n"
- "Click right button to change color,\n"
- "When done drawing, hit key.\n"
- "Press any key to continue\n" );
- getch();
- initgraph(&gdriver,&gmode, "");
- if (graphresult()!=grOk)
- {
- printf( "Graphics Init Error -- EGAVGA.BGI not in "
- "current directory?" );
- return(1);
- }
-
- setcolor(WHITE);
- outtextxy(1,1,"COLOR");
- ActivMouse();
- ShowMouse();
- while (!kbhit())
- {
- ReadMouse(&mouseY,&mouseX,&mouseButton);
- if (mouseButton&BUT1PRESSED)
- {
- if (mouseX!=oldMouseX || mouseY!=oldMouseY)
- {
- // hide mouse cursor before drawing anything!
- HideMouse();
- if (button1Down)
- line(mouseX,mouseY,oldMouseX,oldMouseY);
- oldMouseX=mouseX; oldMouseY=mouseY;
- ShowMouse();
- }
- button1Down=TRUE;
- }
- else
- button1Down=FALSE;
- if (mouseButton&BUT2PRESSED)
- {
- button2Down=TRUE;
- }
- else if (button2Down)
- {
- // If button 2 was down and is now up, it was
- // clicked!
-
-
-
-
-
-
-
-
-
-
-
-
-
- PRODUCT : Borland C++ NUMBER : 1032
- VERSION : 3.x
- OS : DOS
- DATE : October 23, 1992 PAGE : 4/4
-
- TITLE : Example of Mouse Programming in Graphics Mode.
-
-
-
-
- button2Down=FALSE;
-
- // so change the color
- ++currentColor;
-
- if (currentColor==16)
- currentColor=1;
-
- setcolor(currentColor);
- HideMouse();
- outtextxy(1,1,"COLOR");
- ShowMouse();
- }
- }
- closegraph();
- return( 0 );
- }
-
-
-
- DISCLAIMER: You have the right to use this technical information
- subject to the terms of the No-Nonsense License Statement that
- you received with the Borland product to which this information
- pertains.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-